<include file="header" />
<body>
<div class="wraper battering">
    <div class="load">
        <img class="load-bee" src="/assets/base/charging/images/load-bee.png">

    </div>
    <div class="top">
        <p>
            <a href="javascript:history.back();" class="iconfont icon-zuo fl-left"></a>
            {BEESCRM:$app_name}
            <a href="{BEESCRM::U('/Base/Charging/index',array('chargingId'=>$chargingId))}" class="iconfont icon-shouye fl-right"></a>
        </p>
    </div>
    <span class="iconfont icon-chatou"></span>
    <p class="battery">正在充电...</p>
    <p class="battery-time">
        开始时间：{BEESCRM:$data.start_time|date="Y-m-d H:i",###}<br>
        计划充电时长：{BEESCRM:$data.freezing_time}分钟<br>
        已充电时长：<span id="charging-time"></span>
    </p>
    <a href="javascript:void(0)" class="end-btn">结束充电</a>
    <!-- <a href="{BEESCRM::U('/base/charging/index',array('wechat_id'=>$wechat_id))}" class="btn" style="margin-top:30px">返回首页</a> -->
</div>
<input type="hidden" value="{BEESCRM:$data.start_time}000" id="start-timestamp">
<input type="hidden" value="{BEESCRM:$data.charging_log_id}" id="id">
<include file="commonJS" />
<script>
    $(window).load(function(){
        $('.load').hide();
    });

    $(function () {
        var startTime = $('#start-timestamp').val() || $.now();

        (function timer() {
            timeDiff(startTime);
            setTimeout(function () {
                timer();
            }, 1000);
        })();

        function timeDiff(startTime) {
            var diffTime = $.now() - startTime;

            var hour = Math.floor(diffTime/(3600*1000));

            var minutes = Math.floor((diffTime - hour*60*60*1000)/(60*1000));

            var seconds = Math.floor((diffTime - hour*60*60*1000 - minutes*60*1000)/1000);

            $('#charging-time').text(('0' + hour).slice(-3) + '小时 ' + ('0' + minutes).slice(-2) + '分 ' + ('0' + seconds).slice(-2) + '秒 ');

        }
	
        $(document).on('click','.end-btn',function(){
        	$.confirm('您确认要停止充电么',drop);
        	function drop(){
        		var data={};
        		data.charging_log_id=$('#id').val();
        		if(!data.charging_log_id){
        			$.alert('error','参数错误');return;
        		}
    			var json={};
    			json.method='post';
    			json.type='json';
    			json.url="{BEESCRM::U('/base/charging/switch_off',array('chargingId'=>$chargingId))}";
    			json.data=data;
    			$.getAjax(json,true,reload,'');
    		}
        	function reload(){
        		setTimeout('location.href="{BEESCRM::U('/base/charging/index',array('chargingId'=>$chargingId))}"',3000);
        	}
    	});
		
        var A=setInterval(function(){
        	var data={};
        	var json={};
        	data.charging_log_id=$('#id').val();
			json.method='post';
			json.type='json';
			json.url="{BEESCRM::U('/base/charging/checkCharge',array('chargingId'=>$chargingId))}";
			json.data=data;
			$.getAjax(json,false,update,'');
        },10000);
        function update(data){
        	var status=data.status;
        	if(status=='S'){
        		setTimeout('location.href="{BEESCRM::U('/base/charging/index',array('chargingId'=>$chargingId))}"',3000);
        	}
        }
        
    })
</script>
</body>
</html>